//当前登录用户 >= needAuth
import {useRouter} from "vue-router";
import {useStore} from "vuex";
import accessEnum from "@/access/accessEnum";

/**
 *
 * @param loginUser 登录用户
 * @param needAuth  需要权限
 * @return true: 有
 */
const router = useRouter();
const store = useStore();

const checkAccess = (loginUser: any, needAuth = accessEnum.NOT_LOGIN) => {
    const loginUserAccess = loginUser?.userRole ?? accessEnum.NOT_LOGIN;
    // console.log("loginUserAccess => ", loginUserAccess);
    // console.log("needAuth => ", needAuth);
    if(needAuth === accessEnum.NOT_LOGIN) {
        return true;
    }
    if(needAuth === accessEnum.USER) {
        //todo 只需登录
        if(loginUserAccess === accessEnum.NOT_LOGIN) {
            return false;
        }
    }
    if(needAuth === accessEnum.ADMIN) {
        if(loginUserAccess !== accessEnum.ADMIN) {
            return false;
        }
    }
    return true;
}

export default checkAccess;